﻿using Microsoft.Xna.Framework;

namespace Sparklings.Rendering
{
    public class RenderTransform
    {
        public RenderTransform(
            Vector2 renderTargetPixelSize, Vector2 dimensionsInTiles,
            Vector2 upperLeftCornerPositionInTiles = default(Vector2))
        {
            RenderTargetPixelSize = renderTargetPixelSize;
            DimensionsInTiles = dimensionsInTiles;
            UpperLeftCornerPositionInTiles = upperLeftCornerPositionInTiles;
        }
        public Vector2 ToScreenPosition(Vector2 tilePosition)
        {
            return new Vector2(
                (tilePosition.X - UpperLeftCornerPositionInTiles.X) * TilesSizeInPixels.X,
                (tilePosition.Y - UpperLeftCornerPositionInTiles.Y) * TilesSizeInPixels.Y);
        }
        public Vector2 FromScreenPosition(Vector2 screenPosition)
        {
            return new Vector2(
                screenPosition.X / TilesSizeInPixels.X + UpperLeftCornerPositionInTiles.X,
                screenPosition.Y / TilesSizeInPixels.Y + UpperLeftCornerPositionInTiles.Y);
        }

        public Vector2 UpperLeftCornerPositionInTiles { get; set; }
        public Vector2 RenderTargetPixelSize { get; set; }
        public Vector2 DimensionsInTiles { get; set; }
        public Vector2 TilesSizeInPixels { get { return RenderTargetPixelSize / DimensionsInTiles; } }
        public Vector2 OffsetInPixels { get { return UpperLeftCornerPositionInTiles * TilesSizeInPixels; } }
    }
}
